﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;

namespace PacMan
{
    /// <summary>
    /// Indicates the position in which character should move.
    /// </summary>
    enum Position
    {
        Up = 3,
        Left = 1,
        Right = 2,
        Down = 4,
        Stay = 5
    }
    
    /// <summary>
    /// Provides the main logic for all game characters.
    /// </summary>
    abstract class Character : GameObject
    {
        private int _speed;
        private Position _position;

        public Character(int x, int y, int speed) : base(x,y)
        {
            _position = Position.Stay;
            _speed = speed;
        }

        public int DefaultSpeed { get; set; }

        /// <summary>
        /// Gets or sets the current position of the character.
        /// </summary>
        public Position Position 
        {
            get 
            {
                return _position;
            }
            set 
            {
                _position = value;
            }
        }
        /// <summary>
        /// Gets or sets the speed of character.
        /// </summary>
        public int Speed
        {
            get
            {
                return _speed;
            }
            set
            {
                if (value < 0)
                {
                    throw new Exception("Character can't move slower than 0 points per second");
                }

                _speed = value;
            }
        }

        /// <summary>
        /// This method indicates does the character intersects with obstacle.
        /// </summary>
        /// <param name="obstacle">The obstacle which should be checked.</param>
        /// <returns></returns>
        protected bool Obstacles(RectangleF obstacle)
        {
            RectangleF character = new RectangleF(this.X, this.Y, this.Width, this.Height);
            return character.IntersectsWith(obstacle);
        }
    }
}
